<template>

	<view class="content">
		<view class="form">
			<view class="text">{{question}}</view>
			<view class="inputWrapper">
				<input class="input" type="text" 
					placeholder="请输入密保问题答案" maxlength="10"
					@input="input_ans" />
			</view>
			<view class="loginBtn" @click="send">
				<text class="btnText">发送</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//密保问题
				question: "",
				//答案
				ans: "",
				//用户名
				name: "",
			}
		},
		onLoad() {
			//获取密保问题
			uni.getStorage({
				key: 'question',
				success: (res) => {
					this.question = res.data;
				}
			});
			uni.getStorage({
				key: 'name',
				success:(res) => {
					this.name = res.data;
				}
			});
		},
		onHide() {
			//清除问题缓存
			uni.removeStorage({
				key: 'question',
				success: function (res) {
					console.log('success');
				}
			});
		},
		
		methods: {
			//输入密保问题回答
			input_ans(value) {
				this.ans = value.detail.value;
			},
			
			send() {
				console.log(this.ans);
				uni.request({
					url: 'http://192.168.5.3:9091/api/getAnswerCheck', //发送回答
					method:'POST',
					data:{
						name: this.name,
						answer: this.ans,
					},
					success:(res)=> {
						console.log(res.data.code);
						//回答正确
						if(res.data.code == 200){
							uni.redirectTo({
								url:'/pages/forgetPasswords/NewPassword/Newpswd/Newpswd'
							});
							console.log("成功验证");
						}else {
							//回答错误
							uni.showToast({
								title:"回答错误",
								icon:'error',
							})
						}
					}
				})
			}

		},

	}
</script>

<style>
	.content {
		width: 100vw;
		height: 100vh;
		background-color: #f7f8fa;
	}

	.text {
		font-size: 30rpx;
	}

	.form {
		padding: 50upx 100upx;

	}

	.inputWrapper {
		width: 100%;
		height: 80upx;
		border-radius: 20px;
		box-sizing: border-box;
		padding: 0 20px;
		margin-top: 25px;
		background-color: #c8c9cc;

	}

	.inputWrapper .input {
		width: 100%;
		height: 100%;
		text-align: center;
		font-size: 15px;

	}

	.loginBtn {
		width: 100%;
		height: 80upx;
		background: #2979ff;
		border-radius: 50upx;
		margin-top: 30px;
		display: flex;
		justify-content: center;
		align-items: center;

	}

	.bottomBTN {

		width: 100%;

	}

	.loginBtn .btnText {
		color: white;

	}

	.forgotBtn {
		float: left;
		text-align: center;
		color: #2b85e4;
		font-size: 15px;
		margin: 10px;

	}

	.warn {
		color: #fa3534;
		font-size: 25rpx;
		float: inherit;
		margin: 0px;
	}
</style>